// package com.cxy;
//
// import spoon.Launcher;
// import spoon.reflect.code.CtExpression;
// import spoon.reflect.code.CtIf;
// import spoon.reflect.code.CtInvocation;
// import spoon.reflect.declaration.CtClass;
// import spoon.reflect.declaration.CtMethod;
// import spoon.reflect.declaration.CtType;
// import spoon.reflect.reference.CtExecutableReference;
// import spoon.reflect.visitor.filter.AbstractFilter;
// import spoon.reflect.visitor.filter.TypeFilter;
// import spoon.support.reflect.code.CtBinaryOperatorImpl;
// import spoon.support.reflect.code.CtIfImpl;
// import spoon.support.reflect.code.CtInvocationImpl;
//
// import java.util.ArrayList;
// import java.util.Arrays;
// import java.util.HashSet;
// import java.util.List;
// import java.util.Set;
// import java.util.TimeZone;
// import java.util.stream.Collectors;
//
// public class Test {
//     public static void main(String[] args) {
//         String[] availableIDs = TimeZone.getAvailableIDs();
//         System.out.println(Arrays.toString(availableIDs));
//         if (true)return;;
//         String filePath =
//                 "E:\\myIdeawork\\iftsfacade\\src\\main\\java\\com\\hundsun\\ifts\\system\\CtlRole.java"; // 替换为你的 Java 文件路径
//         // filePath = "E:\\myIdeawork\\iftsfacade\\src\\main\\java\\com\\hundsun\\ifts\\app\\batch\\Ctl20002.java";
//         // filePath = "E:\\myIdeawork\\iftsfacade\\src\\main\\java\\com\\hundsun\\ifts\\app\\batch\\Ctl20061.java";
//         filePath = "E:\\myIdeawork\\iftsfacade\\src\\main\\java\\com\\hundsun\\ifts\\system";
//         Launcher launcher = new Launcher();
//         launcher.addInputResource(filePath);
//         launcher.buildModel();
//
//         ArrayList<TestMetedata> lists = new ArrayList<>();
//         for (CtType<?> ctClass : launcher.getFactory().Class().getAll()) {
//             List<ControllerCode> allIfStatements = new ArrayList<>();
//             Set<String> parameterMethodInvocations = new HashSet<>();
//             collectIfStatements((CtClass<?>) ctClass, allIfStatements);
//             findParameterMethodInvocations(ctClass, parameterMethodInvocations);
//             TestMetedata testMetedata =
//                     new TestMetedata(ctClass.getQualifiedName(), parameterMethodInvocations, allIfStatements);
//             lists.add(testMetedata);
//         }
//         for (TestMetedata testMetedata : lists) {
//             System.out.println(testMetedata);
//         }
//     }
//
//     private static void collectIfStatements(CtClass<?> ctClass, List<ControllerCode> ifStatements) {
//         CtMethod<Object> doControl = ctClass.getMethod("doControl");
//         if (doControl == null){
//             return;
//         }
//         doControl.getElements(new TypeFilter<>(CtIf.class)).stream().filter(o1 -> {
//             CtExpression<Boolean> condition1 = o1.getCondition();
//             if (condition1 instanceof CtInvocationImpl){
//                 return extracted((CtInvocationImpl) condition1,"funcId");
//             } else if (condition1 instanceof CtBinaryOperatorImpl) {
//                 List<CtInvocationImpl> allCtInvocationImpl = getAllCtInvocationImpl(condition1);
//                 List<CtInvocationImpl> funcId1 =
//                         allCtInvocationImpl.stream().filter(a -> extracted(a, "funcId")).collect(Collectors.toList());
//                 return !funcId1.isEmpty();
//             }
//             return false;
//         }).forEach(o1->{
//             CtExpression<Boolean> condition1 = o1.getCondition();
//             if (condition1 instanceof CtInvocationImpl){
//                 extracted(ifStatements, (CtIfImpl) o1, (CtInvocationImpl) condition1);
//
//             } else if (condition1 instanceof CtBinaryOperatorImpl) {
//                 List<CtInvocationImpl> allCtInvocationImpl = getAllCtInvocationImpl(condition1);
//                 List<CtInvocationImpl> funcId1 =
//                         allCtInvocationImpl.stream().filter(a -> extracted(a, "funcId")).collect(Collectors.toList());
//                 if (funcId1.size()>1){
//                     for (CtInvocationImpl invocation : funcId1) {
//                         extracted(ifStatements, (CtIfImpl) o1, (CtInvocationImpl) invocation);
//                     }
//
//                 }else{
//                     CtInvocationImpl invocation = funcId1.get(0);
//                     List<CtInvocationImpl> trSubCodes =
//                             allCtInvocationImpl.stream().filter(a -> extracted(a, "trSubCode")).collect(Collectors.toList());
//                     if (trSubCodes.isEmpty()){
//                         System.out.println("");
//                     }
//                     CtInvocationImpl invocation1 = trSubCodes.get(0);
//                     String funcId = getExtracted(invocation, "funcId");
//                     String trSubCode = getExtracted(invocation1, "trSubCode");
//                     ifStatements.add(new ControllerCode(funcId,trSubCode));
//                 }
//
//             }
//         });
//
//     }
//
//     private static void extracted(List<ControllerCode> ifStatements, CtIfImpl o1, CtInvocationImpl condition1) {
//         CtInvocationImpl invocation = condition1;
//         List<CtIf> elements = o1.getThenStatement().getElements(new TypeFilter<>(CtIf.class));
//         ArrayList<CtInvocationImpl> ctInvocations = new ArrayList<>();
//         elements.forEach(oo->{
//             ctInvocations.addAll(getAllCtInvocationImpl(oo.getCondition()));
//         });
//         ctInvocations.stream().filter(a -> {
//             return extracted((CtInvocationImpl) a, "trSubCode");
//         }).collect(Collectors.toList()).forEach(invocation1 ->{
//             String funcId = getExtracted(invocation, "funcId");
//             String trSubCode = getExtracted(invocation1, "trSubCode");
//             ifStatements.add(new ControllerCode(funcId,trSubCode));
//         });
//     }
//
//     private static List<CtInvocationImpl> getAllCtInvocationImpl(CtExpression condition) {
//         if (condition instanceof CtInvocationImpl){
//             CtInvocationImpl invocation = (CtInvocationImpl)condition;
//             return Arrays.asList(invocation);
//         } else if (condition instanceof CtBinaryOperatorImpl) {
//             CtBinaryOperatorImpl invocation = (CtBinaryOperatorImpl)condition;
//             ArrayList<CtInvocationImpl> list1 = new ArrayList<>();
//             list1.addAll(getAllCtInvocationImpl(invocation.getLeftHandOperand()));
//             list1.addAll(getAllCtInvocationImpl(invocation.getRightHandOperand()));
//             return list1;
//         }
//         return new ArrayList<>();
//     }
//
//     private static boolean extracted(CtInvocationImpl condition1,String str) {
//         CtInvocationImpl condition = condition1;
//         ArrayList<String> strings = new ArrayList<>();
//         condition.getArguments().forEach(o2 -> strings.add(o2.toString()));
//         strings.add(condition.getTarget().toString());
//         return strings.contains(str);
//     }
//     private static String getExtracted(CtInvocationImpl condition1,String str) {
//         CtInvocationImpl condition = condition1;
//         ArrayList<String> strings = new ArrayList<>();
//         condition.getArguments().forEach(o2 -> strings.add(o2.toString()));
//         String s = condition.getTarget().toString();
//         if (s.equals(str)){
//             return strings.get(0).toString();
//         }else{
//             return s;
//         }
//     }
//     private static void findParameterMethodInvocations(CtType<?> ctClass, Set<String> parameterMethodInvocations) {
//         ctClass.getElements(new AbstractFilter<CtInvocation<?>>(CtInvocation.class) {
//             @Override
//             public boolean matches(CtInvocation<?> element) {
//                 CtExecutableReference<?> executable = element.getExecutable();
//                 return executable != null && executable.getSimpleName().equals("getParameter");
//             }
//         }).stream().map(o1->o1.getArguments().get(0).toString()).forEach(parameterMethodInvocations::add);
//
//         ctClass.getNestedTypes().forEach(nestedClass -> {
//             findParameterMethodInvocations((CtClass<?>) nestedClass, parameterMethodInvocations);
//         });
//     }
//     static class TestMetedata {
//         String className;
//         Set<String> paramList;
//         List<ControllerCode> controllerCodes;
//
//         public TestMetedata(String className, Set<String> paramList, List<ControllerCode> controllerCodes) {
//             this.className = className;
//             this.paramList = paramList;
//             this.controllerCodes = controllerCodes;
//         }
//
//         @Override
//         public String toString() {
//             return className + "【\n"
//                     + "paramList=" + paramList + "\n"
//                     + "controllerCodes=" + controllerCodes + "\n"
//                     + "】";
//         }
//     }
//     static class ControllerCode {
//         String funId;
//         String subCode;
//
//         public ControllerCode(String funId, String subCode) {
//             this.funId = funId;
//             this.subCode = subCode;
//         }
//
//         @Override
//         public String toString() {
//             return funId + "|" + subCode;
//         }
//     }
// }